/*

    This file is part of Hometree.

    Hometree is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Hometree is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Hometree.  If not, see <http://www.gnu.org/licenses/>.

    Copyright 2011,2012 Roman Held

*/
#ifndef _HTRS_MAP_HEADER_
#define _HTRS_MAP_HEADER_

/********************************************************************\
                            Includes
\********************************************************************/
#include <QObject>
#include <QTcpSocket>
#include <QTimer>
#include "htr/htrglobal.h"

/********************************************************************\
                          Declaration
\********************************************************************/
class HtrsResource;
class HtrsMap : public QObject
{
  Q_OBJECT
  public:
    HtrsMap();
    virtual ~HtrsMap();

    // Suchen/Erstellen einer Ressource:
    HtrsResource *access(const QString &ident, Htr::ResourceType type, bool &created);

    // Alle ermitteln:
    QList<HtrsResource*> resources() const;

  signals:
    // Monitoring:
    void created(HtrsResource *res);
    void changed(HtrsResource *res);
    void aboutToDelete(HtrsResource *res);
    void changesPerSecond(int changes);
 
  private slots:
    void senderChanged();
    void senderAboutToDelete();
    void changesPerSecondStatistics();

  private:
    HtrsResource *create(const QString &ident, Htr::ResourceType type);

    QMap<QString,HtrsResource*> mResources;
    QTimer                      mChangesPerSecondTimer;
    int                         mCurrentChangesPerSecond;  
    int                         mLastChangesPerSecond;  
};

#endif 
